using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using Map2.Xml;

namespace Map2
{
    class Map
    {
        private List<Building> buildings;
        private Size size;
        private MapPanel mapPanel;

        public Map(Size s)
        {
            buildings = new List<Building>();
            size = s;
        }

        public void addBuilding(Point[] points)
        {
            buildings.Add(new Building(points));
            mapPanel.drawBuildings();
        }

        public void loadMap(String filename)
        {
            if(buildings.Count!=0)
                buildings.RemoveRange(0, buildings.Count);
            LoadXml loader = new LoadXml(filename);
            buildings.AddRange(loader.getBuildings());
            setSize(loader.getMapSize());
            mapPanel.drawBuildings();
        }

        public void setPanel(MapPanel panel)
        {
            mapPanel = panel;
            mapPanel.setMapSize(size);
            mapPanel.setBuildings(buildings);
        }

        public void setSize(Size s)
        {
            size = s;
            mapPanel.setMapSize(s);
        }
        public Size getSize()
        {
            return size;
        }

        public void saveMap(string file)
        {
            SaveXml saver = new SaveXml(file, buildings, this.size);
        }

        public List<Building> getBuildings()
        {
            return buildings;
        }

        public MapPanel getMapPanel()
        {
            return mapPanel;
        }
    }
}
